import 'package:flutter/material.dart';
import 'package:mirror/Util.dart';
import 'package:mirror/page/SplashPage.dart';
import 'package:mirror/service/NetworkService.dart';

class TestPage extends StatefulWidget {
  const TestPage({super.key});

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  var controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    controller.text = "http://mirror.ging.plus";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        TextField(
          controller: controller,
          decoration: const InputDecoration.collapsed(hintText: "请输入baseUrl"),
        ),
        ElevatedButton(
          onPressed: () async {
            var navigator = Navigator.of(context);
            if (controller.text.isEmpty) {
              Util.toast("请输入baseurl");
              return;
            }
            await NetworkService.setup(baseUrl: controller.text);
            // navigator.pushReplacement(MaterialPageRoute(builder: (c) => const SplashPage()));
            navigator.pushReplacement(
                MaterialPageRoute(builder: (c) => const SplashPage()));
          },
          child: const Text("启动"),
        ),
      ],
    ));
  }

  @override
  void dispose() {
    super.dispose();
  }
}
